[#ftl]
<style>
label.error {
    color: Red;
    font-size: 13px;
    margin-left: 5px;
    padding-left: 16px;
}
</style>
<script type="text/javascript" src="${base}/js/form-validate.js"></script>
<script type="text/javascript" src="${base}/commonjs/jquery.upload.js" charset="utf-8"></script>
<script type="text/javascript">   

/*弹出提醒框*/
function tips(param){
       var d=dialog({
                content: param,
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
                d.close().remove();
            }, 2000);
            return false;
} 

function changeParent(){
        var selectedId=$("#categoryId").val();
        d=dialog({
            url:'${base}/uyo/platStoreCategory/dataTree?selectedId='+selectedId,  
            title: '选择公司',
          //  background: '#EEE', // 背景色
            opacity: 0.05,  // 透明度
            width: 300,
            height: 350
          });   
          d.show();
}
/*清空父类*/
function cleanParent(){
      $("#parentId").val(null); 
      $("#categoryId").val(null); 
      $("#categoryName").val(''); 
}
</script>
<script type="text/javascript"> 


function butSave(){ 
    $("#parentId").val( $("#categoryId").val() );                        
    $("#dataform").submit();          
 }
  $(function() {
        // 保存
        var v = jQuery("#dataform").validate({
        	errorElement : 'span',  
            errorClass : 'help-block',  
            focusInvalid : false,
             submitHandler: function(form) {
                $(form).ajaxSubmit({
                    url:"${base}/uyo/platStoreCategory/add",
                    success: function(data){  
                        noty({
                          text:extendMessages(data).msg.message,
                          layout:"center",
                          timeout:2000,
                          callback:{
                             afterClose:function(){
               //                         window.parent.d.close().remove();
                                        }
                           }
                        });
                   }
                });
            },
            highlight : function(element) {  
                $(element).closest('.form-group').addClass('has-error');  
            }, 
            errorPlacement : function(error, element) {  
                element.parent('div').append(error);  
            }
       });
       
       $("#butCancel").click(function(){
   //         window.parent.d.close().remove();  
              window.location.reload();          
       });    
  });
  
  
  function  doUploadLogo(){   
    // 上传方法
    $.upload({
        url: '${base}/uyo/platUploadfile/storeFileAdd',// 上传地址
        fileName: 'upfile',// 文件域名字
        params: {"fileTag":3}, // 其他表单数据
        accept:"image/*",
        dataType: 'json', // 上传完成后, 返回json, text
        onSend: function() {// 上传之前回调,return true表示可继续上传
            return true;
        },
        // 上传之后回调
        onComplate: function(data) {
               if(data.state=='ERROR'){
                   tips(data.message);
               }
               else{
	               var imgname = data.url;
	               $("#logoPicPreview").html("<li class='fl ml10' data-type='1'>"
	                +"<div class='image-div'><a href='${base}/"+imgname+"' target='_black'><img class='pb5' src='${base}/"+imgname+"' style='width:150px;height:150px;'></a></div>"
	                +"<div class='pt5'><input type='hidden' value='"+data.fileType+"'>"
	                +"<input type='button' class='select-btn ml10 fr' style='width:40px' onClick='deleteFile(this)' value='删除'></div></li>");        
	               $("#logoId").val(data.fileType);
	               $("#logoUrl").val(imgname);
	           }   
        }
    });
}
</script>
</head>
<body>
<!-- 主要内容开始 -->
 <div class="col-md-11">
    <form id="dataform" role="form" class="form-horizontal"  method="post">
        <input type="hidden" name="parentId" id="parentId" value="${(parent.id)!}">
        <input type="hidden" name="categoryId" id="categoryId" value="${(parent.id)!}">
	  <div class="form-group">
	    <label for="type" class="col-sm-2 control-label">类型</label>
	    <div class="col-sm-6">
	      <select class="form-control" name="type" id="type">
             <option value='1'>公司</option>
             <option value='2' [#if parent?exists && parent.id?exists && parent.id!=0] selected='selected' [/#if]>分店</option>
          </select>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="categoryName" class="col-sm-2 control-label">上级</label>
	    <div class="col-sm-6">
	       <input type="text" class="form-control" id="categoryName" name="categoryName" value="${(parent.name)!''}"  disabled>
	    </div>
           <span class="input-group-btn">
                 <button type="button"  class="btn btn-default"  onclick='changeParent()'>选择</button>
                 <button type="button" class="btn btn-default"  onclick='cleanParent()'>清空</button>
           </span >
	  </div>
	  <div class="form-group">
	    <label for="ownerId" class="col-sm-2 control-label">所属</label>
	    <div class="col-sm-6">
	      [@c.select id="ownerId" attributes="class='form-control'"  datas="store.category.ownerid"/]
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="name" class="col-sm-2 control-label"><span class="red">*</span>名称</label>
	    <div class="col-sm-6">
	      <input type="text" class="required form-control"  maxlength='30' id="name" name="name">
	      <div class="col-sm-6"></div>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="sequence" class="col-sm-2 control-label">序号</label>
	    <div class="col-sm-6">
	      <input type="text" class="number form-control" maxlength='30' id="sequence" name="sequence">
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="sequence" class="col-sm-2 control-label">图标</label>
	    <div class="col-sm-6">
	      
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="status" class="col-sm-2 control-label">状态</label>
	    <div class="col-sm-6">
	      <select name="status" class="form-control">
		    <option value='0'>未审核</option>
            <option value='1'>正常</option>
            <option  value='2'>关闭</option>
          </select>
	    </div>
	  </div>
	  <div class="form-group">
	    <div class="col-sm-offset-2 col-sm-10">
	      <button type="button" class="btn btn-default" onclick="butSave()">保存</button>
	      <button type="button" class="btn btn-default" id="butCancel">取消</button>
	    </div>
	  </div>
	</form>
 </div>   

</body>
</html>